package servlet.orders;

import java.io.IOException;
import java.lang.reflect.InvocationTargetException;
import java.util.Date;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.commons.beanutils.BeanUtils;

import model.Orders;
import model.User;
import service.OrdersService;

/**
 * Servlet implementation class orders_confirm_Servlet
 */
@WebServlet("/orders_confirm")
public class orders_confirm_Servlet extends HttpServlet {

	private	OrdersService oService  = new OrdersService();
	
	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		
		request.setCharacterEncoding("UTF-8");
		Orders o = (Orders) request.getSession().getAttribute("orders");
		try {
			BeanUtils.copyProperties(o,request.getParameterMap());
		} catch (IllegalAccessException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (InvocationTargetException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		
		o.setDatetime(new Date());
		o.setStatus(2);
		o.setUser((User) request.getSession().getAttribute("user"));
		oService.addOrders(o);
		request.getSession().removeAttribute("orders");
		
		request.setAttribute("msg", "订单支付成功!");
		request.getRequestDispatcher("/orders_success.jsp").forward(request, response);
		
	}

}
